new Vue({
    el: '#app',
    data: {
        total: 0,
        pageIndex: 1,
        pageSize: 10,
        pageCon: 1,
        prizeI: '',
        msg: '',
        member: {},
        appealLst: [],
        SERVER_HOST: SERVER_HOST,
        id: ''
    },
    mounted () {
        var member = Cookies.get('member');
        if (!member || member == null || member == '') {
            window.location.href = 'dl.html';
        } else {
            this.member = JSON.parse(member);
            this.load();
        }
    },
    methods: {
        exit () {
            Cookies.remove('member');
            window.location.href = 'dl.html';
        },
        load () {
            let formData = {};
            formData['page'] = this.pageIndex;
            formData['size'] = this.pageSize;
            formData['appealBy'] = this.member['id'];
            getAjax().post('/web/appealList', toFormData(formData)).then(res => {
                if (res.data.data) {
                    this.appealLst = res.data.data.list;
                    this.total = res.data.data.total;
                    this.pageCon = Math.ceil(this.total / this.pageSize);
                    this.appealLst.forEach(item => {
                        item.appealDate = getDate(item.appealDate);
                        if (item.status === '0') {
                            item.statusLabel = '待处理';
                        } else if (item.status === '1') {
                            item.statusLabel = '已处理';
                        } else if (item.status === '2') {
                            item.statusLabel = '已撤销';
                        }
                    });
                }
            });
        },
        pageSelect (pageIndex) {
            if (pageIndex < 1 || pageIndex > this.pageCon) return;
            this.pageIndex = pageIndex;
            this.load();
        },
        appealCancel (id) {
            if (confirm('是否确认撤销申诉？')) {
                getAjax().post('/web/appealCancel', toFormData({id: id})).then(res => {
                    if (res.data.code === 200) {
                        alert('撤销成功！');
                        window.location.reload();
                    }
                });
            }
        }
    }
});
